package com.quwan.manager.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.common.result.PageResult;
import com.quwan.config.yml.OssConfig;
import com.quwan.manager.controller.dto.CircleCommentDto;
import com.quwan.manager.service.ICircleCommentService;
import com.quwan.mapper.TCircleCommentMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author laozhang
 * @date 2022/3/17
 */
@Service
@RequiredArgsConstructor
public class CircleCommentServiceImpl implements ICircleCommentService {

    private final TCircleCommentMapper circleCommentMapper;

    @Override
    public PageResult<CircleCommentDto> getCircleCommentListPage(int page, int size,Long circleId, String beginTime,String endTime) {
        if(StringUtils.isNotBlank(endTime)) {
            endTime = endTime+" 23:59:59";
        }
        Page<CircleCommentDto> circleCommentPage = circleCommentMapper.selectCircleCommentDtoList(new Page<>(page, size),circleId,beginTime,endTime);
        List<CircleCommentDto> reslist = circleCommentPage.getRecords();
        PageResult<CircleCommentDto> result = new PageResult<CircleCommentDto>()
                .setCurrent(circleCommentPage.getCurrent())
                .setPages(circleCommentPage.getPages())
                .setSize(circleCommentPage.getSize())
                .setTotal(circleCommentPage.getTotal())
                .setRecords(reslist);
        return result;
    }

    @Override
    public List<CircleCommentDto> getCircleCommentList(Long circleId,String beginTime, String endTime) {
        if(StringUtils.isNotBlank(endTime)) {
            endTime = endTime+" 23:59:59";
        }
        return circleCommentMapper.selectCircleCommentDtoList(circleId,beginTime,endTime);
    }

    @Override
    public boolean delCircleComment(Long id) {
        return circleCommentMapper.deleteById(id) == 1 ;
    }


}
